﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Xml;
using System.Windows.Forms;

namespace UpdataStart
{
    public static class configTool
    {
        /// <summary>
        /// 更改主程序的配置文件
        /// </summary>
        /// <param name="key"></param>
        /// <param name="newValue"></param>
        public static void GetConfige(string key, string newValue)
        {
            try
            {
                string configFileName = Application.StartupPath + "\\suny.exe.config";//请根据实际情况修改  app.confige发布后就成了.exe.config文件
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.Load(configFileName);
                XmlNodeList nodes = doc.GetElementsByTagName("appSettings");
                foreach (XmlNode node in nodes)
                {
                    XmlElement xe = (XmlElement)node;
                    foreach (XmlElement item in xe.SelectNodes("add"))
                    {

                        if (item.Attributes["key"].Value == key)
                        {
                            item.Attributes["value"].Value = newValue;
                        }

                    }

                }
                doc.Save(configFileName);
            }
            catch (Exception)
            {
                
                throw;
            }
        }
    }
}
